<?php
class upload {
	var $PIC_FILE;
	var $cls_upload_dir;
	var $cls_max_filesize;
	var $cls_filename;
	var $cls_filesize;
	var $cls_arr_ext_accepted;
	var $cls_copyCode;
	var $cls_overWrite;
	
	function upload($inputFileName, $destDir = null, $rename = true) {
		
		global $f;
		$this->cls_upload_dir = $destDir;
		$this->PIC_FILE = $f;
		
		$this->cls_filename = $inputFileName;
		$this->cls_max_filesize = 500000;
		$this->cls_arr_ext_accepted = array (".png", ".gif", ".jpg", ".jpeg", ".tif", ".PNG", ".GIF", ".JPG", ".swf", ".bmp", ".BMP" );
	}
	
	function checkExtension() {
		return (in_array ( $this->get_extension ( $this->cls_filename ), $this->cls_arr_ext_accepted ));
	}
	
	function get_extension($filename) {
		
		return fileext ( $filename );
	}
	
	function checkFileSize() {
		return (! ($this->PIC_FILE ['size'] > $this->cls_max_filesize));
	}
	
	/** removeFile()
	 ** Remove a remote file in upload dir(if we have perms)
	 ** @returns 1 if file was removed, 0 if an error occurred
	 **/
	function removeFile($file) {
		
		if (file_exists ( $this->cls_upload_dir . "/" . $file )) {
			if (@unlink ( $this->cls_upload_dir . "/" . $file )) {
				return (1);
			} else {
				return (0);
			}
		} else {
			return (0);
		}
	}
	
	function checkImage() {
		if (! $this->checkExtension ()) {
			
			return false;
		} elseif (! $this->checkFileSize ()) {
			
			return false;
		} elseif (! is_uploaded_file ( $this->PIC_FILE ['tmp_name'] )) {
			
			return false;
		} else {
			return true;
		}
	}
}
?>